<?php // !class_exists('ujn_model', false) or die('who are u?');

class mdl_bottle_session extends ujn_model {
	
	public function get($iid) {
		$sql =<<<EOT
select `iid`, `uid`, `content`, `created` from {$this->tbl_name}
where `iid` = '{$iid}'
order by created desc;
EOT;
		$res = $this->_db->getAll($sql);
		return $res;
	}
	
	public function say($iid, $uid, $content) {
		$sql =<<<EOT
insert into {$this->tbl_name} set 
`uid` = '{$uid}', `content` = '{$content}',
`iid` = '{$iid}', `created` = unix_timestamp()
EOT;
		$this->_db->query($sql);
		
		$sid = $this->_db->insertID();
		if($sid > 0) mdl_bottle_item::getInstance()->updateSession($iid, $uid);
		return $sid;
	}
	
	protected function __construct() {
		parent::__construct(__CLASS__);
		$this->_db	= $this->mysql();
	}

    /**
     * @return mdl_bottle_session
     */
	static function getInstance() {
		return parent::getInstance(__CLASS__);
	}
}